package com.ruoyi.system.service.impl;

//import com.ruoyi.common.core.domain.entity.HjlyUser;
import com.ruoyi.common.utils.DateUtils;
//import com.ruoyi.common.utils.SecurityUtils;
//import com.ruoyi.common.utils.StringUtils;
//import com.ruoyi.system.constant.HjlyConstants;
import com.ruoyi.system.domain.HjlyAttention;
//import com.ruoyi.hjly.domain.HjlyBar;
//import com.ruoyi.hjly.domain.HjlyMessage;
//import com.ruoyi.hjly.domain.HjlyNew;
import com.ruoyi.system.mapper.HjlyAttentionMapper;
//import com.ruoyi.hjly.mapper.HjlyUserMapper;
//import com.ruoyi.hjly.service.*;
import com.ruoyi.system.service.IHjlyAttentionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 点赞关注收藏Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-03-11
 */
@Service
public class HjlyAttentionServiceImpl implements IHjlyAttentionService
{
    @Autowired
    private HjlyAttentionMapper hjlyAttentionMapper;
//
//    @Autowired
//    private IHjlyMessageService messageService;
//
//    @Autowired
//    private HjlyUserMapper userMapper;
//
//    @Autowired
//    private IHjlyMatchmakerService matchmakerService;
//
//    @Autowired
//    private IHjlyBarService barService;
//
//    @Autowired
//    private IHjlyNewService newService;

    /**
     * 查询点赞关注收藏
     * 
     * @param atId 点赞关注收藏主键
     * @return 点赞关注收藏
     */
    @Override
    public HjlyAttention selectHjlyAttentionByAtId(Integer atId)
    {
        return hjlyAttentionMapper.selectHjlyAttentionByAtId(atId);
    }

    /**
     * 查询点赞关注收藏
     *
     * @param hjlyAttention
     * @return 点赞关注收藏
     */
    @Override
    public HjlyAttention selectHjlyAttentionByAttention(HjlyAttention hjlyAttention) {
        return hjlyAttentionMapper.selectHjlyAttentionByAttention(hjlyAttention);
    }

    /**
     * 查询点赞关注收藏列表
     * 
     * @param hjlyAttention 点赞关注收藏
     * @return 点赞关注收藏
     */
    @Override
    public List<HjlyAttention> selectHjlyAttentionList(HjlyAttention hjlyAttention)
    {
        return hjlyAttentionMapper.selectHjlyAttentionList(hjlyAttention);
    }

    /**
     * 新增点赞关注收藏
     * 
     * @param hjlyAttention 点赞关注收藏
     * @return 结果
     */
    @Override
    @Transactional
    public int insertHjlyAttention(HjlyAttention hjlyAttention)
    {
//        String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
//        Boolean ifSend = true;
//        String relationType = hjlyAttention.getRelationType();//关系类型：1-关注；2-收藏；3-点赞
//        String collectType = hjlyAttention.getCollectType(); //类型：1-用户；2-动态；3-活动 4-新闻
//        HjlyMessage message = new HjlyMessage();
//        message.setMessageType(HjlyConstants.MASSAGE_INTERACT); //互动消息
//        message.setSender(SecurityUtils.getClientUserId());//发送者
//
//        if(StringUtils.equals("1",relationType)){ //关注
//            Long userId = Long.parseLong(hjlyAttention.getTargetId());
//            message.setUserId(userId);
//            HjlyUser hjlyUser = userMapper.selectHjlyUserByUserId(userId);
//            message.setMessageContent(hjlyUser.getNickName()+"关注了你！");
//        }else if(StringUtils.equals("2",relationType)){ //收藏
//            ifSend = false;
//        }else if(StringUtils.equals("3",relationType)){ //点赞
//            if(StringUtils.equals("2",collectType)){ //动态
//                String targetId = hjlyAttention.getTargetId();
//                HjlyBar hjlyBar = barService.selectHjlyBarByBarId(Integer.parseInt(targetId));
//                message.setUserId(hjlyBar.getUserId());
//                message.setCategory(3);//1回复 2评论 3点赞
//                message.setMessageContent(nickName+"点赞了你的动态！");
//            }
//            if(StringUtils.equals("4",collectType)){ //新闻
//                HjlyNew hjlyNew = newService.selectHjlyNewByNewId(Integer.parseInt(hjlyAttention.getTargetId()));
//                if("1".equals(hjlyNew.getSourceType())){
//                    ifSend = false;
//                }else{
//                    message.setUserId(hjlyNew.getUserId());
//                    message.setCategory(3);//1回复 2评论 3点赞
//                    message.setMessageContent(nickName+"点赞了你的新闻！");
//                }
//            }
//        }
//        if(ifSend){
//            messageService.insertHjlyMessage(message);
//        }
        hjlyAttention.setCreateTime(DateUtils.getNowDate());
        return hjlyAttentionMapper.insertHjlyAttention(hjlyAttention);
    }

    /**
     * 修改点赞关注收藏
     * 
     * @param hjlyAttention 点赞关注收藏
     * @return 结果
     */
    @Override
    public int updateHjlyAttention(HjlyAttention hjlyAttention)
    {
        hjlyAttention.setUpdateTime(DateUtils.getNowDate());
        return hjlyAttentionMapper.updateHjlyAttention(hjlyAttention);
    }

    /**
     * 批量删除点赞关注收藏
     * 
     * @param atIds 需要删除的点赞关注收藏主键
     * @return 结果
     */
    @Override
    public int deleteHjlyAttentionByAtIds(Integer[] atIds)
    {
        return hjlyAttentionMapper.deleteHjlyAttentionByAtIds(atIds);
    }

    /**
     * 删除点赞关注收藏信息
     * 
     * @param atId 点赞关注收藏主键
     * @return 结果
     */
    @Override
    public int deleteHjlyAttentionByAtId(Integer atId)
    {
        return hjlyAttentionMapper.deleteHjlyAttentionByAtId(atId);
    }
}
